package com.easy.system.controller;

import com.easy.system.service.BaseService;
import com.easy.system.util.ReflectUtil;
import com.easy.system.validate.FormParamsValidate;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: sunguangzhu
 * Date: 13-7-27
 * Time: 下午5:32
 * To change this template use File | Settings | File Templates.
 */
@Controller
public class AbstractController<T> {
    @Resource
    protected BaseService<T> baseService;
    protected Class controllerClass;
    protected Class clazz;

    public void setControllerClass(Class controllerClass) {
        this.controllerClass = controllerClass;
    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }

    protected void writeToClient(HttpServletResponse response, String jsonStr) throws IOException {
        response.getWriter().write(jsonStr);
    }

    protected T dealFormParams(HttpServletRequest request) throws Exception {
        T entity = (T)FormParamsValidate.validateFrom(request,clazz);
        return entity;
    }


}
